package com.ziven.learn.main

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.ziven.easygo.design.mvp.AbstractModel
import com.ziven.easygo.design.mvp.AbstractOneData
import com.ziven.easygo.ui.AbstractOneDataActivity
import com.ziven.easygo.util.EasyUtils
import com.ziven.easygo.util.LogHelper
import com.ziven.learn.R

class MainActivity : AbstractOneDataActivity() {

    override fun obtainOneModelClass(): Class<out AbstractModel<*>> {
        return MainModel::class.java
    }

    override fun obtainLayout(): Any {
        return R.layout.activity_main
    }

    override fun initLayout() {
        val rv : RecyclerView = getView(R.id.recycler_view)
        rv.layoutManager = LinearLayoutManager(this)
        rv.adapter = MainAdapter()

        LogHelper.of().always().join("initLayout").print()
        onePresenter
            .runOnWorkThread()
            .obtainOneData(this.application)
    }

    override fun layoutOneData(data: AbstractOneData) {
        LogHelper.of().always().join(data).print()
        val adapter = getView<RecyclerView>(R.id.recycler_view).adapter as MainAdapter
        adapter.dataProvider.list = data.getOneData()
        EasyUtils.notifyDataSetChanged(adapter)
    }

    override fun destroyLayout() {

    }
}